package com.xinqi.modules.file.controller;

import com.xinqi.common.core.utils.MessageUtils;
import com.xinqi.common.base.response.R;
import com.xinqi.common.core.utils.StringUtils;
import com.xinqi.common.third.oss.avatar.AvatarOssUtil;
import com.xinqi.common.third.util.TextUtil;
import com.xinqi.modules.file.textimg.service.TextImageService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/file/service")
@RequiredArgsConstructor
public class AvatarController {

    private final TextImageService textImageService;

    @GetMapping("/avatar")
    public R<String> test(String text) {
        String url = textImageService.creatTowTextAvatar(text);
        if (StringUtils.isNotEmpty(url)) {
            return R.ok(url);
        } else {
            return R.fail(MessageUtils.message("user.create.avatar.fail"));
        }
    }

    /**
     * 微信凭证获取
     */
    @GetMapping("/avatar2")
    public R<String> avatar(String text) {
        String url = AvatarOssUtil.creatAvatar(TextUtil.getLastNumStr(text, 2));
        return R.ok(url);
    }
}
